#!/bin/bash
# 安装 mysqlclient - 只安装 MariaDB 开发库（解决冲突）

echo "正在安装 MariaDB 开发库（不安装 mysql-devel 以避免冲突）..."

# 只安装 mariadb-devel（不安装 mysql-devel）
sudo dnf install -y \
    mariadb-devel \
    gcc \
    python3-devel \
    pkgconfig \
    openssl-devel \
    libffi-devel

echo ""
echo "验证安装..."
pkg-config --exists mariadb && echo "✓ MariaDB 开发库已安装" || echo "✗ MariaDB 开发库未找到"

echo ""
echo "查找库文件位置..."
MYSQL_INCLUDE=$(find /usr/include -name "mysql.h" 2>/dev/null | head -1)
MYSQL_LIB=$(find /usr/lib64 -name "libmysqlclient*" 2>/dev/null | head -1)

if [ -n "$MYSQL_INCLUDE" ]; then
    echo "✓ 找到头文件: $MYSQL_INCLUDE"
    MYSQL_INCLUDE_DIR=$(dirname "$MYSQL_INCLUDE")
else
    echo "✗ 未找到 mysql.h"
fi

if [ -n "$MYSQL_LIB" ]; then
    echo "✓ 找到库文件: $MYSQL_LIB"
    MYSQL_LIB_DIR=$(dirname "$MYSQL_LIB")
else
    echo "✗ 未找到 libmysqlclient"
fi

echo ""
echo "如果上面的验证都通过，现在可以安装 mysqlclient："
echo "source venv/bin/activate"
if [ -n "$MYSQL_INCLUDE_DIR" ] && [ -n "$MYSQL_LIB_DIR" ]; then
    echo "export MYSQLCLIENT_CFLAGS=\"-I$MYSQL_INCLUDE_DIR\""
    echo "export MYSQLCLIENT_LDFLAGS=\"-L$MYSQL_LIB_DIR -lmysqlclient\""
fi
echo "pip install mysqlclient"

